//
//  ViewController.swift
//  LLTryFightingApp
//
//  Created by jinbang.li on 2024/9/20.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        createCircleUI()
        
       testOCMethod()
        
        pQueueTestOp()
        
        trieOp()//前缀树应用
        
        leetCodeTest()
    }


}
/**
 controller实现自定义旋转视图
 */
extension ViewController {
    fileprivate func createCircleUI() {
        // 创建 RingView 实例
        let ringView = RingView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
        ringView.center = view.center
        ringView.backgroundColor = .clear // 背景色设置为透明
        view.addSubview(ringView)
                
        // 创建 GradientRingView 实例
           let gradientRingView = GradientRingView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
           gradientRingView.center = view.center
           gradientRingView.backgroundColor = .clear
           view.addSubview(gradientRingView)
        
        
        // 创建 ArcView 实例
        let arcView = ArcView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
        arcView.backgroundColor = .clear
        arcView.center = view.center
        view.addSubview(arcView)

        // 添加旋转动画
        let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
        rotationAnimation.fromValue = 0
        rotationAnimation.toValue = 2 * Double.pi
        rotationAnimation.duration = 2
        rotationAnimation.repeatCount = .infinity
        arcView.layer.add(rotationAnimation, forKey: "rotationAnimation")

    }
}
/**
  测试OC方法
 */
extension ViewController {
    fileprivate func testOCMethod() {
        let test = LLTest()
        test.testMethod()
    }
}
/**
  测试Swift书写常用结构
 */
extension ViewController {
    ///优先队列的操作
    private func pQueueTestOp() {
        var queue = LLPriorityQueue<String,Int>()
        queue.enqueue("任务1", withP: 1)
        queue.enqueue("任务2", withP: 3)
        queue.enqueue("任务3", withP: 2)

        //任务优先级队列 任务2->任务3->任务1
        print(queue.dequeue()!) //
        print(queue.peek()!) //
    }
}
/**
 测试前缀树
 */
extension ViewController {
    private func trieOp() {
        // 示例用法
        let trie = Trie()
        trie.insert("apple")
        print(trie.startsWith("app")) // 输出: true
        print(trie.search("apple")) // 输出: true
        print(trie.search("app"))   // 输出: false
        trie.insert("app")
        print(trie.search("app"))   // 输出: true
    }
}

extension ViewController {
    private func leetCodeTest() {
        ///leetcode 第一题
        let nums = [1,2,3]
        let target = 4
       let result = LLLeetCode.twoSum(nums, target)
        print("result=====\(result)")
        
        ///leetcode第二题
        let lk1 = LLLinkNode(8,nil)
        lk1.next = LLLinkNode(2,LLLinkNode(3,nil))
        
        let lk2 = LLLinkNode(8,nil)
        lk2.next = LLLinkNode(2,LLLinkNode(3,nil))
        
        let lk_result = LLLeetCode.LLTwoNumerSum(lk1, lk2)
        var temp = lk_result
        while temp != nil {
            print("lk_result====\(temp?.value)")
            temp = temp?.next
        }
        
    }
}
